package com.imooc.servlet.servletcontext;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ServletContext - web应用全局对象
 * 页面初始化操作，获得请求的全局对象ServletContext,给全局对象ServletContext设置属性
 */
@WebServlet("/servletcontext/init")
public class ServletContextInit extends HttpServlet {
	private static final long serialVersionUID = 1L;
       



	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获得请求的全局对象ServletContext
		ServletContext context = request.getServletContext();
		//给全局对象context设置属性
		context.setAttribute("copyright", "2018 imooc.com");
		context.setAttribute("title", "慕课网-程序员的梦工厂");
		response.getWriter().println("inti success");
		
	}

}
